package com.fliangyun.nsa.nsamanage.service.impl;

import com.alibaba.fastjson.JSON;
import com.fliangyun.nsa.nsamanage.dao.UserMapper;
import com.fliangyun.nsa.nsamanage.entities.LogInfo;
import com.fliangyun.nsa.nsamanage.entities.User;
import com.fliangyun.nsa.nsamanage.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Rain
 * @date 2023年05月28日
 * @description
 */
@Transactional(readOnly = true)
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private LogInfoServiceImpl logInfoService;

    @Override
    public User getUserByMobile(String mobile) {
        if (StringUtils.isBlank(mobile)){
            return null;
        }
        return userMapper.getUserByMobile(mobile);
    }

    @Transactional
    @Override
    public User saveUser(User user){
        userMapper.saveUser(user);
        LogInfo logInfo = new LogInfo();
        logInfo.setAction("修改用户信息");
        logInfo.setDetail(JSON.toJSONString(user));
        logInfoService.save(logInfo);
        return user;
    }
}
